package com.ffyc.resale.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
@Aspect
public class LogAspect {
    private Logger logger = LoggerFactory.getLogger(LogAspect.class);
    @Before("execution(public * com.ffyc.resale.web..*.*(..))")
    public void savelog(JoinPoint joinPoint) {
        ServletRequestAttributes attributes =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        //Object[] objs =
        joinPoint.getArgs();
        // 记录下请求内容
        logger.info("HTTP_METHOD :{} ", request.getMethod());
        logger.info("IP : {}", request.getRemoteAddr());//客户端ip
    }
}
